home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tagr26d.zip / STRFUNCS.C < prev    next >
C/C++ Source or Header  |  1993-01-24  |  2KB  |  59 lines

  1. /*****************************************************************************\
  2. **                                                                           **
  3. **  Functions to manipulate C and Turbo Pascal strings (for use with T.A.G.  **
  4. **  data files).  Written by Martin Pollard.  Released to public domain.     **
  5. **                                                                           **
  6. **  These functions should work with any MS-DOS C compiler that conforms to  **
  7. **  the ANSI/ISO standards for the C language.  All functions were tested    **
  8. **  with Borland's Turbo C++ v1.0 and Borland C++ v3.1 compilers.            **
  9. **                                                                           **
  10. \*****************************************************************************/
  11.  
  12. #include <ctype.h>
  13. #include <string.h>
  14.  
  15. /*---------------------------------------------------------------------------*/
  16.  
  17. /*
  18. **  strtp2c() - Converts a string from Turbo Pascal format to C format.
  19. **              Any T.A.G. color codes that are present are removed.
  20. */
  21.  
  22. char *strtp2c(char *d, const char *s)
  23. {
  24.     register int i;
  25.     register char *p;
  26.  
  27.     i = 1;
  28.     p = d;
  29.     while (i <= s[0])
  30.     {
  31.         if (i < s[0] && (s[i] == 0x03 || s[i] == '^') &&
  32.             (isdigit(s[i+1]) || (s[i+1] >= 0 && s[i+1] <= 9)))
  33.             ++i;
  34.         else
  35.             *p++ = s[i];
  36.         ++i;
  37.     }
  38.     *p = '\0';
  39.     return(d);
  40. }
  41.  
  42.  
  43. /*---------------------------------------------------------------------------*/
  44.  
  45. /*
  46. **  strc2tp() - Converts a string from C format to Turbo Pascal format.
  47. */
  48.  
  49. char *strc2tp(char *d, char *s)
  50. {
  51.     register int i;
  52.  
  53.     d[0] = strlen(s);
  54.     for (i = d[0]; i > 0; i--)
  55.         d[i] = s[i-1];
  56.     return(d);
  57. }
  58.  
  59.